//
//  MKSystemPhotoCollectionViewCell.swift
//  MKImageBrowser3
//
//  Created by 劢克科技 on 2019/5/10.
//  Copyright © 2019 meckey. All rights reserved.
//  系统相片的Collection Cell

import UIKit
import SnapKit

class MKSystemPhotoCollectionViewCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - Setter
    
    var image: UIImage? {
        didSet {
            imageView.image = self.image
        }
    }
    
    var status: cellStatus = .unselected
    
    func setStatus(selected: Bool) {
        self.checkView.image = selected ? #imageLiteral(resourceName: "selected") : #imageLiteral(resourceName: "unselected")
        self.status = selected ? .selected : .unselected
    }
    
    //MARK: - Getter
    
    enum cellStatus {
        case selected
        case unselected
    }
    
    lazy var imageView: UIImageView = {
        let imageV = UIImageView()
        imageV.contentMode = .scaleAspectFill
        imageV.clipsToBounds = true
        return imageV
    }()
    
    lazy var checkView: UIImageView = {
        let imageV = UIImageView()
        imageV.contentMode = .scaleAspectFill
        imageV.clipsToBounds = true
        imageV.image = #imageLiteral(resourceName: "unselected")
        return imageV
    }()
}

//MARK: - setupUI

extension MKSystemPhotoCollectionViewCell {
    fileprivate func setupUI() {
        addSubs()
        layoutSubs()
    }
    
    fileprivate func addSubs() {
        contentView.addSubview(imageView)
        contentView.addSubview(checkView)
    }
    
    fileprivate func layoutSubs() {
        imageView.snp.makeConstraints { (make) in
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.top.equalTo(contentView.snp_top)
            make.bottom.equalTo(contentView.snp_bottom)
        }
        
        checkView.snp.makeConstraints { (make) in
            make.width.equalTo(22)
            make.height.equalTo(22)
            make.top.equalTo(contentView.snp_top).offset(6)
            make.right.equalTo(contentView.snp_right).offset(-6)
        }
    }
}
